﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EntityListPage.aspx.cs" Inherits="Easy.Web.Pages.EntityPages.EntityListPage" %>

<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head runat="server">
    <title></title>
    <link href="/_css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="/_css/common.css" rel="stylesheet" type="text/css" /> 
    <link rel="stylesheet" type="text/css" href="/_css/iconfont.css" />
    <script src="/_js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="/_js/bootstrap.min.js" type="text/javascript"></script>
    <script src="/_js/json2.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function ()
        {
           

            var entityname = "";

            getEntityList();
            $(".btn-default").hover(function (event) {
                $(this).removeClass("btn-default");
                $(this).addClass("btn-danger");
                //$(this).attr("class", "btn btn-danger");

            },
            function (event) {
                //$(this).attr("class", "btn btn-default");
                $(this).removeClass("btn-danger");
                $(this).addClass("btn-default");
            });

            $("#showModal_btn").click(function () {
                setTimeout("$('#myModal2').modal('show')", 500);    
            });
            
            $("#showModal_btn2").click(function () {
                setTimeout("$('#myModal3').modal('show')", 500);
            });

            $("#showModal_btn3").click(function () {
                //setTimeout("$('#myModal').modal('show')", 500);
                //alert("那我删了~");
                deleteEntity(entityname);
            });


            //横向绑定，填充表头背景
            $("#table-title").parent().css({ "background": "#F5F6FA", "border-top": "1px solid #e1e6eb", "border-bottom": "1px solid #e1e6eb" });
            $("div.table-responsive").scroll(function () {
                var left = (-1)*$(this).scrollLeft();
                $("#table-title").css("left", left);               
            });
            


        });


        function getEntityList()
        {
            $.ajax({
                url: "/Service/Entity/GetEntityList.ashx",
                async: false,
                type: "post",
                dataType: "json",
                data: {
                },
                success: function (data, textStatus)
                {
                    var SMShtml1 = "<table class='table table-hover'>"
                            + " <thead><tr><th>#</th><th>实体英文名</th><th>实体显示名称"
                                               + "  </th><th>实体创建时间</th><th>实体类型</th><th class='table-btn'>"
                                               + "操作</th><th class='table-btn'>记录</th><th class='table-btn'>删除</th><th>实体备注</th></tr></thead></table>";
                    $("#table-title").html(SMShtml1);

                    var SMShtml = "<div id='scroll-table'><table class='table table-hover'><tbody>";

                    for (var i = 0; i < data.length; i++)
                    {
                                                  
                        //id重复了所以改了下
                        var item = data[i];
                        SMShtml += "<tr  name='list' id=\"" + (i + 1) + "\">"
                         + "<td>" + (i + 1) + "</td>"
                        + "<td  id='list_EntityName" + (i + 1) + "'>" + item.EntityName + "</td>"
                        + "<td   id='list_EntityDisplayName" + (i + 1) + "'>" + item.EntityDisplayName + "</td>"                       
                         + "<td   id='list_CreatedOn" + (i + 1) + "'>" + item.CreatedOn + "</td>"
                         + "<td   id='list_type" + (i + 1) + "'>" + item.type + "</td>"
                          + "<td class='table-btn'  id='list_showDetail" + (i + 1) + "'><button type='button' onclick='showDetail(\"" + item.EntityMapId + "\");' class='btn btn-primary'>查看</button></td>"
                           + "<td  class='table-btn' id='list_showRecord" + (i + 1) + "'><button type='button' onclick='showRecord(\"" + item.EntityName + "\");' class='btn btn-primary'>记录</button></td>";
                       
                        
                        var item_type = "自定义实体";
                        if ($.trim(item.type).toString() == item_type) {
                            SMShtml += "<td  class='table-btn' id='list_deleteEntity" + (i + 1) + "'><button type='button' href='#myModal'data-toggle='modal' data-target='#myModal' onclick='getDeleteEntity(\"" + item.EntityName + "\");' class='btn btn-default'>删除</button></td>";
                        }
                        else {
                            //SMShtml += "<td   id='list_blank" + (i + 1) + "'><button type='button' class='btn btn-default disabled'>删除</button></td></td>";
                            SMShtml += "<td  class='table-btn' id='list_blank" + (i + 1) + "'></td>";
                        }
                        SMShtml += "<td   id='list_Desc" + (i + 1) + "'>" + item.Desc + "</td>"
                        SMShtml += "</tr>";
                    }

                    SMShtml += "</tbody></table></div>";

                    $("#entityList_div").html(SMShtml);

                    //滚动table的高度
                    var height=window.innerHeight-183;
                    $("#scroll-table").height(height);
                    

                },
                error: function (data, textStatus)
                {
                    alert("ajax错误");

                }

            });

        }

        function btn_addEntity()
        {
            window.location = "AddEntityPage.aspx";
        }


        function showDetail(id)
        {
            window.location = "AttributeListPage.aspx?Id=" + id;
        }

        function btn_setPrefix()
        {
            window.location = "Setting_Flag.aspx";
        }
        function btn_setGlobal()
        {
            window.location = "GlobalStringMapListPage.aspx";
        }

        function showRecord(name)
        {
            window.open("/Pages/DataPages/View/ViewPage.aspx?entityname=" + name);
        }

        function getDeleteEntity(name) {
            entityname = name;
        }

        function deleteEntity(name) {
            $.ajax({
                url: "/Service/Entity/DeleteEntity.ashx",
                async: true,
                type: "post",
                dataType: "text",
                data: {
                    "EntityName": entityname
                },
                success: function (data) {
                    if (data == "True") {
                        //alert("删除成功...");
                        window.open('/Pages/EntityPages/EntityListPage.aspx', 'main');
                        
                    }
                    else {
                        alert("删除失败");
                    }
                },
                error: function (data) {
                    alert("ajax错误");
                }
            });
        }
        
//滚动table高度响应
        $(window).resize(function () {
            var height = window.innerHeight - 183;
            $("#scroll-table").height(height);
        });
        
        
    </script>
    <style>
        .row{margin-right:0px;}
        .panel{border:none;}
        .page-header{margin:15px;}
        .page-header+.btn-primary{margin:0px 15px 10px 5px;}
        .panel-heading{padding:3px 15px;height:40px;line-height:34px;}
        .table{padding:0;margin:0;border:none;}      
        .table thead th,.table tbody td{width:168px;}      
        .table th.table-btn,.table tbody td.table-btn{width:100px;}
        .table th:first-child,.table tbody td:first-child{width:30px;}
        #entityList_div, #table-title{min-width:1149px;}
        .table-responsive{border:1px solid #e1e6eb;border-top:none;}     
        #table-title{position:relative;}
        #table-title thead tr th{border-bottom:none;}
        @media screen and (max-width: 767px){
            .table-responsive {
                margin-bottom:0px;
                border:none;
                overflow:auto;
                border:1px solid #e1e6eb;
                border-top:none;
            }
        }
    </style>
</head>
<body>
    <form id="form2" runat="server">
    <div class="">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">
                    实体列表
                    <button type='button' style="float: right" id='addEntity' class='btn btn-primary'
                            onclick="btn_addEntity();">
                            新建</button>
                </h1>
                    

            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                   
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="table-responsive" style="overflow:hidden;border-bottom:none;">
                            <div id="table-title">
                            </div>
                        </div>
                        <div class="table-responsive">
                            <div id="entityList_div">
                            </div>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
        </div>
    </div>


        <!-- Button to trigger modal -->
        <!--
        <a href="#" role="button" class="btn" data-toggle="modal" data-target="#myModal">查看演示案例</a>
        -->

        <!-- Modal -->
        <div id="myModal" class="modal fade " tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog" style="width:500px;height:180px;">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h3 id="myModalLabel">提示</h3>
                    </div>
                    <div class="modal-body">
                        <p>确定要删除吗？</p>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
                        <button id="showModal_btn" class="btn btn-primary" data-dismiss="modal">删除</button>
                    </div>
                </div>
            </div>
        </div>

        <div id="myModal2" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true">
            <div class="modal-dialog" style="width:500px;height:180px;">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h3 id="myModalLabel2">提示</h3>
                    </div>
                    <div class="modal-body">
                        <p>真的要删除吗？</p>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
                        <button id="showModal_btn2" class="btn btn-primary" data-dismiss="modal">删除</button>
                    </div>
                </div>
            </div>
        </div>

        <div id="myModal3" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">
            <div class="modal-dialog" style="width:500px;height:180px;">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h3 id="myModalLabel3">提示</h3>
                    </div>
                    <div class="modal-body">
                        <p>最后一次确认要删除吗？</p>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
                        <button id="showModal_btn3" class="btn btn-primary" data-dismiss="modal">删除</button>
                    </div>
                </div>
            </div>
        </div>


    </form>


</body>
</html>
